/**
 * @fileName scripts/webapck.prod.js
 * @description productions|生产环境配置
 */
const getBaseCfg = require('./webpack.base.js');
const { merge } = require('webpack-merge');
const path = require('path');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
let option = merge(getBaseCfg, {
  mode: 'production', // production\development
  devtool: 'hidden-source-map',
  /**
   * @description 优化方案配置
   * @param minimizer |压缩方案配置
   * @param TerserPlugin |压缩JS
   * @param CssMinimizerPlugin |压缩css
   * @param splitChunks |代码切片 (https://webpack.docschina.org/plugins/split-chunks-plugin)
   */
  optimization: {
    minimizer: [
      new CssMinimizerPlugin({
        parallel: true, // 并行压缩
      }),
      new TerserPlugin({
        parallel: true, // 并行压缩
        terserOptions: {
          // compress:true
          compress: {
            pure_funcs: ['console.log', 'console.warn'], //去除
          },
        },
      }),
    ],
    splitChunks: {
      // 缓存配置
      chunks: 'async',
      minSize: 20000,
      minChunks: 1,
      // 由于在这个示例中单个 HTML 页面有多个入口，所以添加了 optimization.runtimeChunk: 'single' 配置，否则可能会遇到 这个问题。查看 代码分割 章节了解更多细节
      // runtimeChunk: 'single',
      cacheGroups: {
        vendors: {
          priority: 1,
          test: /node_modules/,
          name: 'vendors',
        },
        commons: {
          name: 'commons',
          minChunks: 3,
        },
      },
    },
  },
});
module.exports = option;
